import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class GoodsRecommend extends StatelessWidget {
  List recommendList;

  GoodsRecommend(this.recommendList);

//标题
  Widget _title() {
    return Container(
      padding: EdgeInsets.fromLTRB(10, 5, 10, 5),
      alignment: Alignment.centerLeft,
      margin: EdgeInsets.only(top: 10),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(bottom: BorderSide(width: 1, color: Colors.black12))),
      child: Text(
        "商品推荐",
        style: TextStyle(color: Colors.pink),
      ),
    );
  }

  Widget _item(index) {
    return InkWell(
      onTap: () {},
      child: Container(
        height: ScreenUtil().setHeight(100),
        width: ScreenUtil().setWidth(125),
        padding: EdgeInsets.all(3),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(left: BorderSide(width: 1, color: Colors.black12))),
        child: Column(
          children: <Widget>[
            Image.network(recommendList[index]['image']),
            Text("￥${recommendList[index]['mallPrice']}"),
            Text(
              "￥${recommendList[index]['price']}",
              style: TextStyle(
                  color: Colors.grey, decoration: TextDecoration.lineThrough),
            )
          ],
        ),
      ),
    );
  }

  Widget _recommendList() {
    return Container(
        height: ScreenUtil().setHeight(210),
        child: ListView.builder(
          scrollDirection: Axis.horizontal,
          itemBuilder: (context, index) {
            return _item(index);
          },
          itemCount: recommendList.length,
        ));
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[_title(), _recommendList()],
      ),
    );
  }
}
